package main

import (
	"fmt"
	"runtime"
	"time"
)

func init() {
	fmt.Println("逻辑cpu数量", runtime.NumCPU()) //获取逻辑cpu数量
	n := runtime.GOMAXPROCS(10)              //设置cpu数量[1,256]
	fmt.Println(n)
}

func main() {
	//获取goroot目录
	fmt.Println("goroot目录", runtime.GOROOT(), "系统型号", runtime.GOOS)

	go func() {
		gotest()
		fmt.Println("test")
		for i := 0; i < 5; i++ {
			fmt.Println("gorutine")
		}
	}()

	//time.Sleep(2*time.Second)

	//go gotest()
	time.Sleep(1 * time.Second)

	for i := 0; i < 4; i++ {
		runtime.Gosched()
		fmt.Println("main")
	}

}

func gotest() {
	defer fmt.Println("defer")
	runtime.Goexit() //结束其所在的线程
	fmt.Println("gotest")
}
